package com.gitee.huanminabc.utils_tools.log_extend.logback;

import ch.qos.logback.classic.pattern.ClassicConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;
import com.gitee.huanminabc.jcommon.base.SnowIdUtil;
import com.gitee.huanminabc.jcommon.str.StringUtil;
import com.gitee.huanminabc.utils_tools.log_extend.LogTraceContextHolder;

/**
 * @author 胡安民
 * 扩展对logback的日志链路生成
 */
public class LogTraceConvert extends ClassicConverter {

    @Override
    public String convert(ILoggingEvent iLoggingEvent) {
        String traceId = LogTraceContextHolder.get();
        if (StringUtil.isEmpty(traceId)){
            traceId = SnowIdUtil.uniqueLongHex();
        }
        return traceId;
    }
}
